//bitmap version
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;

//sort length unique intergers in s[] range from 1 to range (range>=length)
int* unique_sort(int S[],int length,int range)
{
  vector<bool> bitmap(range);
  for(int i=0; i<length; i++)
    bitmap[S[i]] = true;
  for(int i=0,j=0; i<range; i++)
    if(bitmap[i]) 
      S[j++] = i;
  return S;
}

int main()
{
  int a[] = {1,10,3,4,2,6,8,7,5,9};

  int* b = unique_sort(a,10,20);

  copy(a,a+10,ostream_iterator<int>(cout," ") );
  cout<<endl;
  copy(b,b+10,ostream_iterator<int>(cout," ") );
  cout<<endl;

  return 0;
}
